<template>
    <bSearch :instance="mSearch"></bSearch>
    <div class="blank"></div>
    <bList :instance="pList"></bList>
    <Dialog v-model="dForm._show" :title="dForm.title" :destroyOnClose="true">
        <bForm :instance="dForm" cover="50%">
            <Button @click="onUpdate">完成</Button>
        </bForm>
    </Dialog>
</template>

<script setup lang="ts">
import { IList, IForm, IListSearch } from "@b/index/department";
import bList from "@m/components/public/b_list.vue";
import bSearch from "@m/components/public/b_search.vue";
import bForm from "@m/components/public/b_form.vue";
import { Dialog, Button } from "vant";
/* import-and-register */

const mSearch = new IListSearch();
const pList = new IList();
const dForm = new IForm();
/* const-and-register */

dForm.init();
mSearch.init();

mSearch.onSearch = () => {
    //解构（浅拷贝，防止存在查询条件时点击页码产生的混乱）
    pList.search_key = mSearch.getData();
    pList.refresh(1);
};

pList.edit = async (id: number) => {
    if (!id) return;
    dForm._show = true;
    dForm.id = id;
    dForm.title = "修改区域列表信息";
    await dForm.setData();
};
pList.add = async () => {
    dForm._show = true;
    dForm.title = "添加部门";
};
const onUpdate = async () => {
    const res = await dForm.updateData();
    if (res) {
        dForm._show = false;
        pList.refresh();
    }
};
/* event-and-register */
</script>